// 
// SoapTrace.Net - A soap message monitoring utility. 
// 
// Copyright (C) 2004-2009 Matthew Ward
// 
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
// 
// Matthew Ward (mrward@users.sourceforge.net)
// 

using System;
using System.Diagnostics;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace SoapTrace
{
	public partial class OptionsForm : Form
	{
		/// <summary>
		/// The options editor.
		/// </summary>
		private SoapTraceOptionsEditor m_Editor;

		/// <summary>
		/// Creates a new instance of the options form.
		/// </summary>
		public OptionsForm( SoapTraceOptionsEditor editor )
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent( );

			m_Editor = editor;
		}

		/// <summary>
		/// Adds formatter names to the list box.
		/// </summary>
		/// <param name="names">The array of formatter names.</param>
		public void AddFormatters( string[ ] names )
		{
			foreach( string Name in names )
			{
				AddFormatter( Name );
			}
		}

		/// <summary>
		/// Adds a formatter name to the list box.
		/// </summary>
		/// <param name="name">The formatter's name.</param>
		public void AddFormatter( string name )
		{
			FormattersListBox.Items.Add( name );
		}

		/// <summary>
		/// Gets or sets the formatter options button enabled state.
		/// </summary>
		public bool FormatterOptionsButtonEnabled
		{
			[ DebuggerStepThrough ]
			get
			{
				return OptionsButton.Enabled;
			}

			[ DebuggerStepThrough ]
			set
			{
				OptionsButton.Enabled = value;
			}
		}
		
		/// <summary>
		/// Gets or sets whether logging is enabled.
		/// </summary>
		public bool LoggingEnabled
		{
			get
			{
				return LoggingEnabledCheckBox.Checked;
			}
			
			set
			{
				LoggingEnabledCheckBox.Checked = value;
			}
		}
		
		/// <summary>
		/// Gets or sets the logging folder.
		/// </summary>
		public string LogFolder
		{
			get
			{
				return LogFolderTextBox.Text;
			}
			
			set
			{
				LogFolderTextBox.Text = value;
			}
		}
		
		/// <summary>
		/// Gets or sets whether the application will be displayed in the tray.
		/// </summary>
		public bool ShowInTray
		{
			get
			{
				return ShowInTrayCheckBox.Checked;
			}
			
			set
			{
				ShowInTrayCheckBox.Checked = value;
			}
		}

		/// <summary>
		/// Handles the cancel button click event.
		/// </summary>
		private void OptionsCancelButtonClick( object sender, EventArgs e )
		{
			m_Editor.UndoChanges( );
			Close( );
		}

		/// <summary>
		/// Handles the OK button click event.
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void OptionsOKButtonClick( object sender, EventArgs e )
		{
			m_Editor.SaveChanges( );
			Close( );
		}

		/// <summary>
		/// Handles the options button click event.
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void OptionsButtonClick( object sender, EventArgs e )
		{
			m_Editor.ShowFormatterOptions( ( string )FormattersListBox.SelectedItem );
		}

		/// <summary>
		/// Handles the event when the user selects an item in the list box.
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void FormattersListBoxSelectedIndexChanged( object sender, 
			EventArgs e )
		{
			m_Editor.FormatterSelected( ( string )FormattersListBox.SelectedItem );
		}
		
		/// <summary>
		/// Handles the event when the user clicks the browse button.
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void LoggingFolderBrowseButtonClick( object sender, EventArgs e )
		{
			m_Editor.BrowseForLoggingFolder( );
		}		
	}
}
